"""
Observable.py

Author: Miles Malerba
Date: 9-20-08

$Id: Observable.py 326 2008-10-17 02:23:55Z malerba89 $
"""

class Observable(object):
    """abstract class that acts as the subject of an observer patter.
       can update observers when changes occur. based off code from
       Wikipedia: http://en.wikipedia.org/wiki/Observer_pattern#Python
    """
    
    def __init__(self):
        """constructor"""
        self.observers = []
        
    def register_observer(self, observer):
        """register a new observer with this subject"""
        self.observers.append(observer)
 
    def unregister_observer(self, observer):
        """unregister an observer with this subject"""
        self.observers.remove(observer)
 
    def notify_observers(self, param=None):
        """notify all observers that a change has occurred.
           optional param allows more info to be sent
        """
        for observer in self.observers:
            observer.update(self, param)
